package openGl;

import android.opengl.GLES20;

/**
 * Created by Administrator on 2017/12/25.
 */

public class OpenGlUtils {
    /**
     * 顶点着色器
     */
    public static final String vertexShaderCode = "attribute vec4 a_Position;     \t\t\n" +
            "\n" +
            "void main()                    \n" +
            "{                              \n" +
            "    gl_Position = a_Position;\n" +
            "    gl_PointSize = 10.0;\n" +
            "}   ";
    /**
     * 片元着色器
     */
    public static final String fragmentShaderCode ="precision mediump float; \n" +
            "      \t \t\t\t\t\t\t\t\t\n" +
            "uniform vec4 u_Color;          \t   \t\t\t\t\t\t\t\t\n" +
            "  \n" +
            "void main()                    \t\t\n" +
            "{                              \t\n" +
            "    gl_FragColor = u_Color;                                  \t\t\n" +
            "}";
    /**
     * 加载生成着色器
     * @param type
     * @param shaderCode
     * @return
     */
    public static int loadShader(int type, String shaderCode){
        //根据type创建顶点着色器或者片元着色器
        int shader = GLES20.glCreateShader(type);
        //将资源加入到着色器中，并编译
        GLES20.glShaderSource(shader, shaderCode);
        GLES20.glCompileShader(shader);
        return shader;
    }
}
